<?php

namespace adminmatrix\server\app\lists;

trait ListsOrderTrait
{
    protected string $order;
    protected array $orderField;

    public function initOrder()
    {
        $this->orderField =   $this->request->get('orderField', ['id'=>'desc']);
        if ($this->orderField)
        {
            $parentClass = @class_parents($this->model);
            if (isset($parentClass['adminmatrix\server\app\model\BaseModel']) && $this->isSearch)
            {
                if (!empty($this->order))
                {
                    $this->orderField  = array_push($this->orderField, $this->order);

                }
                $this->model->order($this->orderField );
            }
        }
    }
}